﻿//-----------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Microsoft.LibraryManagerDemo.Controls
{
    /// <summary>
    /// Represents a special skin-aware message box for displaying error messages.
    /// </summary>
    public partial class ErrorBox : Window
    {
        #region Initializers

        /// <summary>
        /// Initialize new instance of this type.
        /// </summary>
        public ErrorBox()
        {
            InitializeComponent();

            DataContext = this;
        }

        #endregion

        #region Static Methods

        /// <summary>
        /// Displays an error message box.
        /// </summary>
        /// <param name="error">The error message to display.</param>
        /// <param name="caption">The caption of the error box.</param>
        /// <param name="owner">The owner window of this error box.</param>
        public static void Show(string error, string caption, Window owner)
        {
            ErrorBox errorBox = new ErrorBox()
            {
                Caption = caption,
                Error = error,
                Owner = owner
            };

            if (errorBox.Owner != null)
            {
                errorBox.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }

            errorBox.ShowDialog();
        }

        /// <summary>
        /// Displays an error message box.
        /// </summary>
        /// <param name="error">The error message to display.</param>
        /// <param name="caption">The caption of the error box.</param>
        public static void Show(string error, string caption)
        {
            Show(error, caption, null);
        }

        #endregion

        #region Dependency Properties

        #region Caption Property

        /// <value>Identifies the Caption dependency property.</value>
        public static readonly DependencyProperty CaptionProperty =
            DependencyProperty.Register("Caption", typeof(string), typeof(ErrorBox),
            new FrameworkPropertyMetadata("Error"));

        /// <value>Gets or sets the error box caption.</value>
        public string Caption
        {
            get { return (string)GetValue(CaptionProperty); }
            set { SetValue(CaptionProperty, value); }
        }

        #endregion

        #region Error Property

        /// <value>Identifies the Error dependency property.</value>
        public static readonly DependencyProperty ErrorProperty =
            DependencyProperty.Register("Error", typeof(string), typeof(ErrorBox),
            new FrameworkPropertyMetadata(string.Empty));

        /// <value>Gets or sets the error message.</value>
        public string Error
        {
            get { return (string)GetValue(ErrorProperty); }
            set { SetValue(ErrorProperty, value); }
        }

        #endregion
        
        #endregion

        #region Event Handlers

        /// <summary>
        /// Close this error box.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        void Button_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
        
        #endregion
    }
}
